package cc.dd.marketing.reward.rule.checker;

import cc.dd.marketing.reward.dto.RewardGivingDTO;
import cc.dd.marketing.reward.rule.domain.StockRemainRule;
import cc.dd.marketing.rule.base.RuleChecker;
import cc.dd.marketing.system.exception.base.BusinessException;
import cc.dd.marketing.system.exception.response.ResultCodeEnum;
import org.springframework.stereotype.Component;

/**
 * 剩余库存规则校验
 *
 * @author dongsufeng
 * @date 2022/9/9 11:39 AM
 */
@Component
public class StockRemainRuleChecker implements RuleChecker<StockRemainRule, RewardGivingDTO> {


    @Override
    public Boolean validate(StockRemainRule rule, RewardGivingDTO request) {
        if (rule.getRule()==null  || rule.getRule() <= 0) {
            throw new BusinessException(ResultCodeEnum.RULE_CHECK_FAIL.getCode(), "剩余库存小于等于0");
        }
        return true;
    }
}
